package cn.sdormitory.controller.smartdor;


import cn.sdormitory.basedata.entity.BStudent;
import cn.sdormitory.basedata.service.BStudentService;
import cn.sdormitory.common.annotation.IgnoreAuth;
import cn.sdormitory.common.annotation.SysLog;
import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.common.enums.BusinessType;
import cn.sdormitory.smartdor.entity.AdManualAttence;
import cn.sdormitory.smartdor.entity.SdAttence;
import cn.sdormitory.smartdor.service.SdManualAttenceService;
import cn.sdormitory.smartdor.vo.SdAttenceStudentVo;
import cn.sdormitory.smartdor.vo.SdManualAttenceVo;
import cn.sdormitory.sys.entity.SysMenu;
import cn.sdormitory.sys.service.SysDictDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "Smartdor-ManualAttence=> 人工考勤管理")
@RequestMapping("/smartdor/manualsdAttence")
public class SdManualAttenceController {

    @Resource
    private SdManualAttenceService sdManualAttenceService;

    @Resource
    private BStudentService bStudentService;

    @ApiOperation("list => 查询人工考勤列表")
    @PreAuthorize("@ss.hasPermi('smartdor:manualsdattence:list')")
    @GetMapping(value = "/manualsdattenceList")
    public CommonResult<List<SdManualAttenceVo>> list() throws ParseException {
        //return CommonResult.success(sdAttenceService.getPage(params));
        System.out.println("开始执行人工考勤 ....... ");
        List<SdManualAttenceVo> manualAttenceVoList = sdManualAttenceService.getManualAttenceList();
        // System.out.println("返回的栋号信息： " +manualAttenceVoList);
//        for (SdManualAttenceVo attenceVo : manualAttenceVoList) {
//            System.out.println(attenceVo);
//        }

        return CommonResult.success(manualAttenceVoList);

    }

    @IgnoreAuth
    @ApiOperation("{dormitoryNo}=>宿舍ID")
//    @GetMapping("/getStuByDormitoryNo/{dormitoryNo}")
//    public CommonResult<List<SdAttenceStudentVo>> getStuByDormitoryNo(@PathVariable("dormitoryNo") String dormitoryNo) {
    @GetMapping("/getStuByDormitoryNo")
    public CommonResult<List<SdAttenceStudentVo>> getStuByDormitoryNo(String accessDate, String bdormitoryId) {
        //List<BStudent> studentList = bStudentService.getBStudentByDormitoryId(Long.parseLong(dormitoryNo));
        //System.out.println("accessDate  考勤时间： "+accessDate+" dormitoryNo ："+bdormitoryId);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        List<SdAttenceStudentVo> studentList = sdManualAttenceService.getBStudentAttenceByAccessDateAdnDormitoryId(accessDate,Long.parseLong(bdormitoryId));
//        System.out.println("...... studentList : " + studentList.size());
//        for (SdAttenceStudentVo vo : studentList){
//            System.out.println("name : "+vo.getStudentName() +"\t status : "+vo.getAttenceStatus());
//        }
        return CommonResult.success(studentList);
    }

    @ApiOperation("create => 新增人工考勤信息")
    @PreAuthorize("@ss.hasPermi('smartdor:manualsdattence:add')")
    @PostMapping(value = "/create")
    public CommonResult<Integer> create(@RequestBody AdManualAttence adManualAttence) throws IOException {

        //System.out.println("attenceDate :" + adManualAttence);

        int count = sdManualAttenceService.addManualAttence(adManualAttence);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
        //System.out.println("attenceDate :" + attenceDate + "\t studentIdArray: " + studentIdArray + "\t statusArray :" + statusArray);
    }


}